#!/bin/bash -e

# Date 		: 2021.02.27
# Author	: majin
# Mail 		: xx
# Function	: test for xx
# Version 	: 1.0
# Update 	: 2021.02.27

RES="\033[0m"
GREEN="\033[32m"
BLUE="\033[36m"
PURPLE="\033[35m"
RED="\033[31m"

name_msg(){ echo -e "${GREEN}name_msg:  [ `readlink -f $0` ] ${RES}";}
info_msg(){ echo -e "${BLUE}info_msg: $1 ${RES}";}
warn_msg(){ echo -e "${PURPLE}warn_msg: $1 ${RES}";}

function get_cmd_pid(){
    ps -ef | grep "${1}" | grep -v grep | awk '{print $2}'
}

function ps_cmd_stop(){
    now_pid=$(get_cmd_pid ${1})
    info_msg "${1} now pid = ${now_pid}"
    if [[ ${now_pid} ]];then
        kill -15 ${now_pid}
        sleep 1
        now_pid=$(get_cmd_pid ${1})
    fi
    
    info_msg "${1} success to stop, now_pid=${now_pid}"
}

function ps_cmd_status(){
    now_pid=$(get_cmd_pid ${1})
    
    info_msg "${1} now_pid = ${now_pid}"
}

# 清理缓存
function clean_up_cache(){
    info_msg "echo 3 > /proc/sys/vm/drop_caches"
    echo 3 > /proc/sys/vm/drop_caches
}

function prepare_test_env(){
    source /home/majin/set_env.sh
    get_now_gcc_path=`dirname $(which gcc)`
    echo "new gcc: ${get_now_gcc_path}"
    sleep 5
}